<!-- 修改密码 -->
<template>
	<view>
		<view class="container">
		    <input class="text-box" placeholder="请输入当前密码"   v-model="currentPassword"/>
		    <input class="text-box" type='password' placeholder="请输入新密码" v-model="newPassword"/>
		    <input class="text-box" type='password' placeholder="确认新密码"   v-model="confirmPassword"/>
		    <button class="button" @click="savePassword">保存</button>
		  </view>
	</view>
</template>

<script>
	import {resetPassword} from '@/api/login.js';
	import { removeToken } from '@/util/auth.js'; 
	export default {
		data() {
			return {
				currentPassword: '',
				newPassword: '',
				confirmPassword: '',
				req:{},
				userId:0
			}
		},
		onLoad(options) {
			this.userId=options.userId
		},
		methods: {
			savePassword() {
			      if (this.newPassword === this.confirmPassword) {
			        // 新密码和确认密码相同，执行保存操作
			        console.log('密码匹配，执行保存操作');
					this.req.newPassword=this.newPassword;
					this.req.oldPassword=this.currentPassword;
					this.req.id=this.userId;
					resetPassword(this.req).then(res=>{
						console.log(res);
						if(res.data.code===20000){
							removeToken()
							// 关闭所有页面返回到登录页
							uni.reLaunch({
								url: '/pages/index/login/login'
							})
						}
					})
			        // 这里可以添加保存密码到服务器或本地存储的逻辑
			      } else {
					uni.showToast({
					        title: '密码不匹配，请重新输入',
					        icon: 'none',
					    });
					return; 
			        // 这里可以添加显示错误信息的逻辑
			      }
			    }
		}
	}
</script>

<style>
.container {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  height: 100vh; /* 可根据需要调整高度 */
  padding: 16px;
  box-sizing: border-box;
}
 
.text-box {
  background-color: #e1e1e1; /* 灰色背景 */
  border: none;
  padding: 10px;
  margin: 8px 0;
  height: 50px;
  border-radius: 5px;
  box-sizing: border-box;
  width: 100%; /* 使其宽度充满父容器 */
}
 
.button {
  background-color: #c88200; /* 按钮背景颜色 */
  color: white;
  border: none;
  padding: 10px;
  text-align: center;
  margin-top: 10px;
  width: 100%; /* 使其宽度充满父容器 */
}
</style>
